package main

import (
	"fmt"
	"time"
)

func main() {
	count := make(chan int, 4)
	fin := make(chan bool)

	go func() {
		defer func() { fin <- true }()
		for i := 0; i < 10; i++ {
			count <- i
			time.Sleep(1 * time.Second)
		}
	}()

	for {
		select {
		case n := <-count:
			fmt.Println("count =", n)
		case <-fin:
			fmt.Println("结束")
			goto END
			// default:
			// 	fmt.Println("缺省")
		}
	}
END:
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}
